#!/usr/bin/env python3
# coding: utf-8
import jwt

from .logger import get_logger

from config import config as CONFIG

logger = get_logger(__name__)


def parser_token(raw_token: str):
    token = raw_token.strip()
    try:
        payload = jwt.decode(jwt=token, key=CONFIG.SECRET_KEY)
    except Exception as e:
        logger.error("TOKEN parsing exceptions: {}".format(e))
        uid, login_type = 0, 0
        return False, uid, login_type

    uid = payload.get('uid')
    login_type = payload.get('ltp')
    return True, uid, login_type
